<?php
/**
 * Created by PhpStorm.
 * User: Lxx<779219930@qq.com>
 * Date: 2018/9/20
 * Time: 14:46
 */

namespace app\home\model;


use think\Db;
use think\Model;

class Collect extends Base
{
    protected $insert = [
        'create_time' => NOW_TIME,
        'score' => 1,
        'status' => 0,
    ];

    /**
     * 判断是否收藏
     */
    public function getCollect($type,$aid,$uid) {
        $map = array(
            'type' => $type,
            'aid' => $aid,
            'uid' => $uid,
        );
        $like = $this->where($map)->find();
        ($like) ? $res = 1 : $res = 0;
        return $res;
    }
    
    /**
     * 获取我的收藏
     */
    public function getMyCollect($uid,$len = 0) {
        $list = $this->where(['uid' => $uid])->order('create_time desc')->limit($len,8)->select();
        foreach ($list as $value) {
            $msg = Db::table("pb_".$value['table'])->where(['id' => $value['aid']])->find();
            if($msg['front_cover']) {
                $msg['path'] = $this->get_cover($msg['front_cover']);
            }
            $value['detail'] = $msg;
        }
        return $list;
    }
}